
_ls:     file format elf32-i386


Disassembly of section .text:

00000000 <fmtname>:
#include "user.h"
#include "fs.h"

char*
fmtname(char *path)
{
       0:	55                   	push   %ebp
       1:	89 e5                	mov    %esp,%ebp
       3:	53                   	push   %ebx
       4:	83 ec 24             	sub    $0x24,%esp
  static char buf[DIRSIZ+1];
  char *p;
  
  // Find first character after last slash.
  for(p=path+strlen(path); p >= path && *p != '/'; p--)
       7:	8b 45 08             	mov    0x8(%ebp),%eax
       a:	89 04 24             	mov    %eax,(%esp)
       d:	e8 e4 03 00 00       	call   3f6 <strlen>
      12:	8b 55 08             	mov    0x8(%ebp),%edx
      15:	01 d0                	add    %edx,%eax
      17:	89 45 f4             	mov    %eax,-0xc(%ebp)
      1a:	eb 04                	jmp    20 <fmtname+0x20>
      1c:	83 6d f4 01          	subl   $0x1,-0xc(%ebp)
      20:	8b 45 f4             	mov    -0xc(%ebp),%eax
      23:	3b 45 08             	cmp    0x8(%ebp),%eax
      26:	72 0a                	jb     32 <fmtname+0x32>
      28:	8b 45 f4             	mov    -0xc(%ebp),%eax
      2b:	0f b6 00             	movzbl (%eax),%eax
      2e:	3c 2f                	cmp    $0x2f,%al
      30:	75 ea                	jne    1c <fmtname+0x1c>
    ;
  p++;
      32:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
  
  // Return blank-padded name.
  if(strlen(p) >= DIRSIZ)
      36:	8b 45 f4             	mov    -0xc(%ebp),%eax
      39:	89 04 24             	mov    %eax,(%esp)
      3c:	e8 b5 03 00 00       	call   3f6 <strlen>
      41:	83 f8 0d             	cmp    $0xd,%eax
      44:	76 05                	jbe    4b <fmtname+0x4b>
    return p;
      46:	8b 45 f4             	mov    -0xc(%ebp),%eax
      49:	eb 5f                	jmp    aa <fmtname+0xaa>
  memmove(buf, p, strlen(p));
      4b:	8b 45 f4             	mov    -0xc(%ebp),%eax
      4e:	89 04 24             	mov    %eax,(%esp)
      51:	e8 a0 03 00 00       	call   3f6 <strlen>
      56:	89 44 24 08          	mov    %eax,0x8(%esp)
      5a:	8b 45 f4             	mov    -0xc(%ebp),%eax
      5d:	89 44 24 04          	mov    %eax,0x4(%esp)
      61:	c7 04 24 c0 16 00 00 	movl   $0x16c0,(%esp)
      68:	e8 13 05 00 00       	call   580 <memmove>
  memset(buf+strlen(p), ' ', DIRSIZ-strlen(p));
      6d:	8b 45 f4             	mov    -0xc(%ebp),%eax
      70:	89 04 24             	mov    %eax,(%esp)
      73:	e8 7e 03 00 00       	call   3f6 <strlen>
      78:	ba 0e 00 00 00       	mov    $0xe,%edx
      7d:	89 d3                	mov    %edx,%ebx
      7f:	29 c3                	sub    %eax,%ebx
      81:	8b 45 f4             	mov    -0xc(%ebp),%eax
      84:	89 04 24             	mov    %eax,(%esp)
      87:	e8 6a 03 00 00       	call   3f6 <strlen>
      8c:	05 c0 16 00 00       	add    $0x16c0,%eax
      91:	89 5c 24 08          	mov    %ebx,0x8(%esp)
      95:	c7 44 24 04 20 00 00 	movl   $0x20,0x4(%esp)
      9c:	00 
      9d:	89 04 24             	mov    %eax,(%esp)
      a0:	e8 78 03 00 00       	call   41d <memset>
  return buf;
      a5:	b8 c0 16 00 00       	mov    $0x16c0,%eax
}
      aa:	83 c4 24             	add    $0x24,%esp
      ad:	5b                   	pop    %ebx
      ae:	5d                   	pop    %ebp
      af:	c3                   	ret    

000000b0 <ls>:

void
ls(char *path)
{
      b0:	55                   	push   %ebp
      b1:	89 e5                	mov    %esp,%ebp
      b3:	57                   	push   %edi
      b4:	56                   	push   %esi
      b5:	53                   	push   %ebx
      b6:	81 ec 5c 02 00 00    	sub    $0x25c,%esp
  char buf[512], *p;
  int fd;
  struct dirent de;
  struct stat st;
  
  if((fd = open(path, 0)) < 0){
      bc:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
      c3:	00 
      c4:	8b 45 08             	mov    0x8(%ebp),%eax
      c7:	89 04 24             	mov    %eax,(%esp)
      ca:	e8 35 05 00 00       	call   604 <open>
      cf:	89 45 e4             	mov    %eax,-0x1c(%ebp)
      d2:	83 7d e4 00          	cmpl   $0x0,-0x1c(%ebp)
      d6:	79 20                	jns    f8 <ls+0x48>
    printf(2, "ls: cannot open %s\n", path);
      d8:	8b 45 08             	mov    0x8(%ebp),%eax
      db:	89 44 24 08          	mov    %eax,0x8(%esp)
      df:	c7 44 24 04 b2 11 00 	movl   $0x11b2,0x4(%esp)
      e6:	00 
      e7:	c7 04 24 02 00 00 00 	movl   $0x2,(%esp)
      ee:	e8 6e 06 00 00       	call   761 <printf>
      f3:	e9 01 02 00 00       	jmp    2f9 <ls+0x249>
    return;
  }
  
  if(fstat(fd, &st) < 0){
      f8:	8d 85 bc fd ff ff    	lea    -0x244(%ebp),%eax
      fe:	89 44 24 04          	mov    %eax,0x4(%esp)
     102:	8b 45 e4             	mov    -0x1c(%ebp),%eax
     105:	89 04 24             	mov    %eax,(%esp)
     108:	e8 0f 05 00 00       	call   61c <fstat>
     10d:	85 c0                	test   %eax,%eax
     10f:	79 2b                	jns    13c <ls+0x8c>
    printf(2, "ls: cannot stat %s\n", path);
     111:	8b 45 08             	mov    0x8(%ebp),%eax
     114:	89 44 24 08          	mov    %eax,0x8(%esp)
     118:	c7 44 24 04 c6 11 00 	movl   $0x11c6,0x4(%esp)
     11f:	00 
     120:	c7 04 24 02 00 00 00 	movl   $0x2,(%esp)
     127:	e8 35 06 00 00       	call   761 <printf>
    close(fd);
     12c:	8b 45 e4             	mov    -0x1c(%ebp),%eax
     12f:	89 04 24             	mov    %eax,(%esp)
     132:	e8 b5 04 00 00       	call   5ec <close>
     137:	e9 bd 01 00 00       	jmp    2f9 <ls+0x249>
    return;
  }
  
  switch(st.type){
     13c:	0f b7 85 bc fd ff ff 	movzwl -0x244(%ebp),%eax
     143:	98                   	cwtl   
     144:	83 f8 01             	cmp    $0x1,%eax
     147:	74 53                	je     19c <ls+0xec>
     149:	83 f8 02             	cmp    $0x2,%eax
     14c:	0f 85 9c 01 00 00    	jne    2ee <ls+0x23e>
  case T_FILE:
    printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size);
     152:	8b bd cc fd ff ff    	mov    -0x234(%ebp),%edi
     158:	8b b5 c4 fd ff ff    	mov    -0x23c(%ebp),%esi
     15e:	0f b7 85 bc fd ff ff 	movzwl -0x244(%ebp),%eax
     165:	0f bf d8             	movswl %ax,%ebx
     168:	8b 45 08             	mov    0x8(%ebp),%eax
     16b:	89 04 24             	mov    %eax,(%esp)
     16e:	e8 8d fe ff ff       	call   0 <fmtname>
     173:	89 7c 24 14          	mov    %edi,0x14(%esp)
     177:	89 74 24 10          	mov    %esi,0x10(%esp)
     17b:	89 5c 24 0c          	mov    %ebx,0xc(%esp)
     17f:	89 44 24 08          	mov    %eax,0x8(%esp)
     183:	c7 44 24 04 da 11 00 	movl   $0x11da,0x4(%esp)
     18a:	00 
     18b:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
     192:	e8 ca 05 00 00       	call   761 <printf>
    break;
     197:	e9 52 01 00 00       	jmp    2ee <ls+0x23e>
  
  case T_DIR:
    if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf){
     19c:	8b 45 08             	mov    0x8(%ebp),%eax
     19f:	89 04 24             	mov    %eax,(%esp)
     1a2:	e8 4f 02 00 00       	call   3f6 <strlen>
     1a7:	83 c0 10             	add    $0x10,%eax
     1aa:	3d 00 02 00 00       	cmp    $0x200,%eax
     1af:	76 19                	jbe    1ca <ls+0x11a>
      printf(1, "ls: path too long\n");
     1b1:	c7 44 24 04 e7 11 00 	movl   $0x11e7,0x4(%esp)
     1b8:	00 
     1b9:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
     1c0:	e8 9c 05 00 00       	call   761 <printf>
      break;
     1c5:	e9 24 01 00 00       	jmp    2ee <ls+0x23e>
    }
    strcpy(buf, path);
     1ca:	8b 45 08             	mov    0x8(%ebp),%eax
     1cd:	89 44 24 04          	mov    %eax,0x4(%esp)
     1d1:	8d 85 e0 fd ff ff    	lea    -0x220(%ebp),%eax
     1d7:	89 04 24             	mov    %eax,(%esp)
     1da:	e8 a2 01 00 00       	call   381 <strcpy>
    p = buf+strlen(buf);
     1df:	8d 85 e0 fd ff ff    	lea    -0x220(%ebp),%eax
     1e5:	89 04 24             	mov    %eax,(%esp)
     1e8:	e8 09 02 00 00       	call   3f6 <strlen>
     1ed:	8d 95 e0 fd ff ff    	lea    -0x220(%ebp),%edx
     1f3:	01 d0                	add    %edx,%eax
     1f5:	89 45 e0             	mov    %eax,-0x20(%ebp)
    *p++ = '/';
     1f8:	8b 45 e0             	mov    -0x20(%ebp),%eax
     1fb:	c6 00 2f             	movb   $0x2f,(%eax)
     1fe:	83 45 e0 01          	addl   $0x1,-0x20(%ebp)
    while(read(fd, &de, sizeof(de)) == sizeof(de)){
     202:	e9 c0 00 00 00       	jmp    2c7 <ls+0x217>
      if(de.inum == 0)
     207:	0f b7 85 d0 fd ff ff 	movzwl -0x230(%ebp),%eax
     20e:	66 85 c0             	test   %ax,%ax
     211:	0f 84 af 00 00 00    	je     2c6 <ls+0x216>
        continue;
      memmove(p, de.name, DIRSIZ);
     217:	c7 44 24 08 0e 00 00 	movl   $0xe,0x8(%esp)
     21e:	00 
     21f:	8d 85 d0 fd ff ff    	lea    -0x230(%ebp),%eax
     225:	83 c0 02             	add    $0x2,%eax
     228:	89 44 24 04          	mov    %eax,0x4(%esp)
     22c:	8b 45 e0             	mov    -0x20(%ebp),%eax
     22f:	89 04 24             	mov    %eax,(%esp)
     232:	e8 49 03 00 00       	call   580 <memmove>
      p[DIRSIZ] = 0;
     237:	8b 45 e0             	mov    -0x20(%ebp),%eax
     23a:	83 c0 0e             	add    $0xe,%eax
     23d:	c6 00 00             	movb   $0x0,(%eax)
      if(stat(buf, &st) < 0){
     240:	8d 85 bc fd ff ff    	lea    -0x244(%ebp),%eax
     246:	89 44 24 04          	mov    %eax,0x4(%esp)
     24a:	8d 85 e0 fd ff ff    	lea    -0x220(%ebp),%eax
     250:	89 04 24             	mov    %eax,(%esp)
     253:	e8 8f 02 00 00       	call   4e7 <stat>
     258:	85 c0                	test   %eax,%eax
     25a:	79 20                	jns    27c <ls+0x1cc>
        printf(1, "ls: cannot stat %s\n", buf);
     25c:	8d 85 e0 fd ff ff    	lea    -0x220(%ebp),%eax
     262:	89 44 24 08          	mov    %eax,0x8(%esp)
     266:	c7 44 24 04 c6 11 00 	movl   $0x11c6,0x4(%esp)
     26d:	00 
     26e:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
     275:	e8 e7 04 00 00       	call   761 <printf>
        continue;
     27a:	eb 4b                	jmp    2c7 <ls+0x217>
      }
      printf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size);
     27c:	8b bd cc fd ff ff    	mov    -0x234(%ebp),%edi
     282:	8b b5 c4 fd ff ff    	mov    -0x23c(%ebp),%esi
     288:	0f b7 85 bc fd ff ff 	movzwl -0x244(%ebp),%eax
     28f:	0f bf d8             	movswl %ax,%ebx
     292:	8d 85 e0 fd ff ff    	lea    -0x220(%ebp),%eax
     298:	89 04 24             	mov    %eax,(%esp)
     29b:	e8 60 fd ff ff       	call   0 <fmtname>
     2a0:	89 7c 24 14          	mov    %edi,0x14(%esp)
     2a4:	89 74 24 10          	mov    %esi,0x10(%esp)
     2a8:	89 5c 24 0c          	mov    %ebx,0xc(%esp)
     2ac:	89 44 24 08          	mov    %eax,0x8(%esp)
     2b0:	c7 44 24 04 da 11 00 	movl   $0x11da,0x4(%esp)
     2b7:	00 
     2b8:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
     2bf:	e8 9d 04 00 00       	call   761 <printf>
     2c4:	eb 01                	jmp    2c7 <ls+0x217>
    strcpy(buf, path);
    p = buf+strlen(buf);
    *p++ = '/';
    while(read(fd, &de, sizeof(de)) == sizeof(de)){
      if(de.inum == 0)
        continue;
     2c6:	90                   	nop
      break;
    }
    strcpy(buf, path);
    p = buf+strlen(buf);
    *p++ = '/';
    while(read(fd, &de, sizeof(de)) == sizeof(de)){
     2c7:	c7 44 24 08 10 00 00 	movl   $0x10,0x8(%esp)
     2ce:	00 
     2cf:	8d 85 d0 fd ff ff    	lea    -0x230(%ebp),%eax
     2d5:	89 44 24 04          	mov    %eax,0x4(%esp)
     2d9:	8b 45 e4             	mov    -0x1c(%ebp),%eax
     2dc:	89 04 24             	mov    %eax,(%esp)
     2df:	e8 f8 02 00 00       	call   5dc <read>
     2e4:	83 f8 10             	cmp    $0x10,%eax
     2e7:	0f 84 1a ff ff ff    	je     207 <ls+0x157>
        printf(1, "ls: cannot stat %s\n", buf);
        continue;
      }
      printf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size);
    }
    break;
     2ed:	90                   	nop
  }
  close(fd);
     2ee:	8b 45 e4             	mov    -0x1c(%ebp),%eax
     2f1:	89 04 24             	mov    %eax,(%esp)
     2f4:	e8 f3 02 00 00       	call   5ec <close>
}
     2f9:	81 c4 5c 02 00 00    	add    $0x25c,%esp
     2ff:	5b                   	pop    %ebx
     300:	5e                   	pop    %esi
     301:	5f                   	pop    %edi
     302:	5d                   	pop    %ebp
     303:	c3                   	ret    

00000304 <main>:

int
main(int argc, char *argv[])
{
     304:	55                   	push   %ebp
     305:	89 e5                	mov    %esp,%ebp
     307:	83 e4 f0             	and    $0xfffffff0,%esp
     30a:	83 ec 20             	sub    $0x20,%esp
  int i;

  if(argc < 2){
     30d:	83 7d 08 01          	cmpl   $0x1,0x8(%ebp)
     311:	7f 11                	jg     324 <main+0x20>
    ls(".");
     313:	c7 04 24 fa 11 00 00 	movl   $0x11fa,(%esp)
     31a:	e8 91 fd ff ff       	call   b0 <ls>
    exit();
     31f:	e8 a0 02 00 00       	call   5c4 <exit>
  }
  for(i=1; i<argc; i++)
     324:	c7 44 24 1c 01 00 00 	movl   $0x1,0x1c(%esp)
     32b:	00 
     32c:	eb 1f                	jmp    34d <main+0x49>
    ls(argv[i]);
     32e:	8b 44 24 1c          	mov    0x1c(%esp),%eax
     332:	8d 14 85 00 00 00 00 	lea    0x0(,%eax,4),%edx
     339:	8b 45 0c             	mov    0xc(%ebp),%eax
     33c:	01 d0                	add    %edx,%eax
     33e:	8b 00                	mov    (%eax),%eax
     340:	89 04 24             	mov    %eax,(%esp)
     343:	e8 68 fd ff ff       	call   b0 <ls>

  if(argc < 2){
    ls(".");
    exit();
  }
  for(i=1; i<argc; i++)
     348:	83 44 24 1c 01       	addl   $0x1,0x1c(%esp)
     34d:	8b 44 24 1c          	mov    0x1c(%esp),%eax
     351:	3b 45 08             	cmp    0x8(%ebp),%eax
     354:	7c d8                	jl     32e <main+0x2a>
    ls(argv[i]);
  exit();
     356:	e8 69 02 00 00       	call   5c4 <exit>
     35b:	90                   	nop

0000035c <stosb>:
               "cc");
}

static inline void
stosb(void *addr, int data, int cnt)
{
     35c:	55                   	push   %ebp
     35d:	89 e5                	mov    %esp,%ebp
     35f:	57                   	push   %edi
     360:	53                   	push   %ebx
  asm volatile("cld; rep stosb" :
     361:	8b 4d 08             	mov    0x8(%ebp),%ecx
     364:	8b 55 10             	mov    0x10(%ebp),%edx
     367:	8b 45 0c             	mov    0xc(%ebp),%eax
     36a:	89 cb                	mov    %ecx,%ebx
     36c:	89 df                	mov    %ebx,%edi
     36e:	89 d1                	mov    %edx,%ecx
     370:	fc                   	cld    
     371:	f3 aa                	rep stos %al,%es:(%edi)
     373:	89 ca                	mov    %ecx,%edx
     375:	89 fb                	mov    %edi,%ebx
     377:	89 5d 08             	mov    %ebx,0x8(%ebp)
     37a:	89 55 10             	mov    %edx,0x10(%ebp)
               "=D" (addr), "=c" (cnt) :
               "0" (addr), "1" (cnt), "a" (data) :
               "memory", "cc");
}
     37d:	5b                   	pop    %ebx
     37e:	5f                   	pop    %edi
     37f:	5d                   	pop    %ebp
     380:	c3                   	ret    

00000381 <strcpy>:
#include "user.h"
#include "x86.h"

char*
strcpy(char *s, char *t)
{
     381:	55                   	push   %ebp
     382:	89 e5                	mov    %esp,%ebp
     384:	83 ec 10             	sub    $0x10,%esp
  char *os;

  os = s;
     387:	8b 45 08             	mov    0x8(%ebp),%eax
     38a:	89 45 fc             	mov    %eax,-0x4(%ebp)
  while((*s++ = *t++) != 0)
     38d:	90                   	nop
     38e:	8b 45 0c             	mov    0xc(%ebp),%eax
     391:	0f b6 10             	movzbl (%eax),%edx
     394:	8b 45 08             	mov    0x8(%ebp),%eax
     397:	88 10                	mov    %dl,(%eax)
     399:	8b 45 08             	mov    0x8(%ebp),%eax
     39c:	0f b6 00             	movzbl (%eax),%eax
     39f:	84 c0                	test   %al,%al
     3a1:	0f 95 c0             	setne  %al
     3a4:	83 45 08 01          	addl   $0x1,0x8(%ebp)
     3a8:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
     3ac:	84 c0                	test   %al,%al
     3ae:	75 de                	jne    38e <strcpy+0xd>
    ;
  return os;
     3b0:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
     3b3:	c9                   	leave  
     3b4:	c3                   	ret    

000003b5 <strcmp>:

int
strcmp(const char *p, const char *q)
{
     3b5:	55                   	push   %ebp
     3b6:	89 e5                	mov    %esp,%ebp
  while(*p && *p == *q)
     3b8:	eb 08                	jmp    3c2 <strcmp+0xd>
    p++, q++;
     3ba:	83 45 08 01          	addl   $0x1,0x8(%ebp)
     3be:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
}

int
strcmp(const char *p, const char *q)
{
  while(*p && *p == *q)
     3c2:	8b 45 08             	mov    0x8(%ebp),%eax
     3c5:	0f b6 00             	movzbl (%eax),%eax
     3c8:	84 c0                	test   %al,%al
     3ca:	74 10                	je     3dc <strcmp+0x27>
     3cc:	8b 45 08             	mov    0x8(%ebp),%eax
     3cf:	0f b6 10             	movzbl (%eax),%edx
     3d2:	8b 45 0c             	mov    0xc(%ebp),%eax
     3d5:	0f b6 00             	movzbl (%eax),%eax
     3d8:	38 c2                	cmp    %al,%dl
     3da:	74 de                	je     3ba <strcmp+0x5>
    p++, q++;
  return (uchar)*p - (uchar)*q;
     3dc:	8b 45 08             	mov    0x8(%ebp),%eax
     3df:	0f b6 00             	movzbl (%eax),%eax
     3e2:	0f b6 d0             	movzbl %al,%edx
     3e5:	8b 45 0c             	mov    0xc(%ebp),%eax
     3e8:	0f b6 00             	movzbl (%eax),%eax
     3eb:	0f b6 c0             	movzbl %al,%eax
     3ee:	89 d1                	mov    %edx,%ecx
     3f0:	29 c1                	sub    %eax,%ecx
     3f2:	89 c8                	mov    %ecx,%eax
}
     3f4:	5d                   	pop    %ebp
     3f5:	c3                   	ret    

000003f6 <strlen>:

uint
strlen(char *s)
{
     3f6:	55                   	push   %ebp
     3f7:	89 e5                	mov    %esp,%ebp
     3f9:	83 ec 10             	sub    $0x10,%esp
  int n;

  for(n = 0; s[n]; n++)
     3fc:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
     403:	eb 04                	jmp    409 <strlen+0x13>
     405:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
     409:	8b 55 fc             	mov    -0x4(%ebp),%edx
     40c:	8b 45 08             	mov    0x8(%ebp),%eax
     40f:	01 d0                	add    %edx,%eax
     411:	0f b6 00             	movzbl (%eax),%eax
     414:	84 c0                	test   %al,%al
     416:	75 ed                	jne    405 <strlen+0xf>
    ;
  return n;
     418:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
     41b:	c9                   	leave  
     41c:	c3                   	ret    

0000041d <memset>:

void*
memset(void *dst, int c, uint n)
{
     41d:	55                   	push   %ebp
     41e:	89 e5                	mov    %esp,%ebp
     420:	83 ec 0c             	sub    $0xc,%esp
  stosb(dst, c, n);
     423:	8b 45 10             	mov    0x10(%ebp),%eax
     426:	89 44 24 08          	mov    %eax,0x8(%esp)
     42a:	8b 45 0c             	mov    0xc(%ebp),%eax
     42d:	89 44 24 04          	mov    %eax,0x4(%esp)
     431:	8b 45 08             	mov    0x8(%ebp),%eax
     434:	89 04 24             	mov    %eax,(%esp)
     437:	e8 20 ff ff ff       	call   35c <stosb>
  return dst;
     43c:	8b 45 08             	mov    0x8(%ebp),%eax
}
     43f:	c9                   	leave  
     440:	c3                   	ret    

00000441 <strchr>:

char*
strchr(const char *s, char c)
{
     441:	55                   	push   %ebp
     442:	89 e5                	mov    %esp,%ebp
     444:	83 ec 04             	sub    $0x4,%esp
     447:	8b 45 0c             	mov    0xc(%ebp),%eax
     44a:	88 45 fc             	mov    %al,-0x4(%ebp)
  for(; *s; s++)
     44d:	eb 14                	jmp    463 <strchr+0x22>
    if(*s == c)
     44f:	8b 45 08             	mov    0x8(%ebp),%eax
     452:	0f b6 00             	movzbl (%eax),%eax
     455:	3a 45 fc             	cmp    -0x4(%ebp),%al
     458:	75 05                	jne    45f <strchr+0x1e>
      return (char*)s;
     45a:	8b 45 08             	mov    0x8(%ebp),%eax
     45d:	eb 13                	jmp    472 <strchr+0x31>
}

char*
strchr(const char *s, char c)
{
  for(; *s; s++)
     45f:	83 45 08 01          	addl   $0x1,0x8(%ebp)
     463:	8b 45 08             	mov    0x8(%ebp),%eax
     466:	0f b6 00             	movzbl (%eax),%eax
     469:	84 c0                	test   %al,%al
     46b:	75 e2                	jne    44f <strchr+0xe>
    if(*s == c)
      return (char*)s;
  return 0;
     46d:	b8 00 00 00 00       	mov    $0x0,%eax
}
     472:	c9                   	leave  
     473:	c3                   	ret    

00000474 <gets>:

char*
gets(char *buf, int max)
{
     474:	55                   	push   %ebp
     475:	89 e5                	mov    %esp,%ebp
     477:	83 ec 28             	sub    $0x28,%esp
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
     47a:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
     481:	eb 46                	jmp    4c9 <gets+0x55>
    cc = read(0, &c, 1);
     483:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
     48a:	00 
     48b:	8d 45 ef             	lea    -0x11(%ebp),%eax
     48e:	89 44 24 04          	mov    %eax,0x4(%esp)
     492:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     499:	e8 3e 01 00 00       	call   5dc <read>
     49e:	89 45 f0             	mov    %eax,-0x10(%ebp)
    if(cc < 1)
     4a1:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
     4a5:	7e 2f                	jle    4d6 <gets+0x62>
      break;
    buf[i++] = c;
     4a7:	8b 55 f4             	mov    -0xc(%ebp),%edx
     4aa:	8b 45 08             	mov    0x8(%ebp),%eax
     4ad:	01 c2                	add    %eax,%edx
     4af:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
     4b3:	88 02                	mov    %al,(%edx)
     4b5:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
    if(c == '\n' || c == '\r')
     4b9:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
     4bd:	3c 0a                	cmp    $0xa,%al
     4bf:	74 16                	je     4d7 <gets+0x63>
     4c1:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
     4c5:	3c 0d                	cmp    $0xd,%al
     4c7:	74 0e                	je     4d7 <gets+0x63>
gets(char *buf, int max)
{
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
     4c9:	8b 45 f4             	mov    -0xc(%ebp),%eax
     4cc:	83 c0 01             	add    $0x1,%eax
     4cf:	3b 45 0c             	cmp    0xc(%ebp),%eax
     4d2:	7c af                	jl     483 <gets+0xf>
     4d4:	eb 01                	jmp    4d7 <gets+0x63>
    cc = read(0, &c, 1);
    if(cc < 1)
      break;
     4d6:	90                   	nop
    buf[i++] = c;
    if(c == '\n' || c == '\r')
      break;
  }
  buf[i] = '\0';
     4d7:	8b 55 f4             	mov    -0xc(%ebp),%edx
     4da:	8b 45 08             	mov    0x8(%ebp),%eax
     4dd:	01 d0                	add    %edx,%eax
     4df:	c6 00 00             	movb   $0x0,(%eax)
  return buf;
     4e2:	8b 45 08             	mov    0x8(%ebp),%eax
}
     4e5:	c9                   	leave  
     4e6:	c3                   	ret    

000004e7 <stat>:

int
stat(char *n, struct stat *st)
{
     4e7:	55                   	push   %ebp
     4e8:	89 e5                	mov    %esp,%ebp
     4ea:	83 ec 28             	sub    $0x28,%esp
  int fd;
  int r;

  fd = open(n, O_RDONLY);
     4ed:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
     4f4:	00 
     4f5:	8b 45 08             	mov    0x8(%ebp),%eax
     4f8:	89 04 24             	mov    %eax,(%esp)
     4fb:	e8 04 01 00 00       	call   604 <open>
     500:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(fd < 0)
     503:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     507:	79 07                	jns    510 <stat+0x29>
    return -1;
     509:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
     50e:	eb 23                	jmp    533 <stat+0x4c>
  r = fstat(fd, st);
     510:	8b 45 0c             	mov    0xc(%ebp),%eax
     513:	89 44 24 04          	mov    %eax,0x4(%esp)
     517:	8b 45 f4             	mov    -0xc(%ebp),%eax
     51a:	89 04 24             	mov    %eax,(%esp)
     51d:	e8 fa 00 00 00       	call   61c <fstat>
     522:	89 45 f0             	mov    %eax,-0x10(%ebp)
  close(fd);
     525:	8b 45 f4             	mov    -0xc(%ebp),%eax
     528:	89 04 24             	mov    %eax,(%esp)
     52b:	e8 bc 00 00 00       	call   5ec <close>
  return r;
     530:	8b 45 f0             	mov    -0x10(%ebp),%eax
}
     533:	c9                   	leave  
     534:	c3                   	ret    

00000535 <atoi>:

int
atoi(const char *s)
{
     535:	55                   	push   %ebp
     536:	89 e5                	mov    %esp,%ebp
     538:	83 ec 10             	sub    $0x10,%esp
  int n;

  n = 0;
     53b:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
  while('0' <= *s && *s <= '9')
     542:	eb 23                	jmp    567 <atoi+0x32>
    n = n*10 + *s++ - '0';
     544:	8b 55 fc             	mov    -0x4(%ebp),%edx
     547:	89 d0                	mov    %edx,%eax
     549:	c1 e0 02             	shl    $0x2,%eax
     54c:	01 d0                	add    %edx,%eax
     54e:	01 c0                	add    %eax,%eax
     550:	89 c2                	mov    %eax,%edx
     552:	8b 45 08             	mov    0x8(%ebp),%eax
     555:	0f b6 00             	movzbl (%eax),%eax
     558:	0f be c0             	movsbl %al,%eax
     55b:	01 d0                	add    %edx,%eax
     55d:	83 e8 30             	sub    $0x30,%eax
     560:	89 45 fc             	mov    %eax,-0x4(%ebp)
     563:	83 45 08 01          	addl   $0x1,0x8(%ebp)
atoi(const char *s)
{
  int n;

  n = 0;
  while('0' <= *s && *s <= '9')
     567:	8b 45 08             	mov    0x8(%ebp),%eax
     56a:	0f b6 00             	movzbl (%eax),%eax
     56d:	3c 2f                	cmp    $0x2f,%al
     56f:	7e 0a                	jle    57b <atoi+0x46>
     571:	8b 45 08             	mov    0x8(%ebp),%eax
     574:	0f b6 00             	movzbl (%eax),%eax
     577:	3c 39                	cmp    $0x39,%al
     579:	7e c9                	jle    544 <atoi+0xf>
    n = n*10 + *s++ - '0';
  return n;
     57b:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
     57e:	c9                   	leave  
     57f:	c3                   	ret    

00000580 <memmove>:

void*
memmove(void *vdst, void *vsrc, int n)
{
     580:	55                   	push   %ebp
     581:	89 e5                	mov    %esp,%ebp
     583:	83 ec 10             	sub    $0x10,%esp
  char *dst, *src;
  
  dst = vdst;
     586:	8b 45 08             	mov    0x8(%ebp),%eax
     589:	89 45 fc             	mov    %eax,-0x4(%ebp)
  src = vsrc;
     58c:	8b 45 0c             	mov    0xc(%ebp),%eax
     58f:	89 45 f8             	mov    %eax,-0x8(%ebp)
  while(n-- > 0)
     592:	eb 13                	jmp    5a7 <memmove+0x27>
    *dst++ = *src++;
     594:	8b 45 f8             	mov    -0x8(%ebp),%eax
     597:	0f b6 10             	movzbl (%eax),%edx
     59a:	8b 45 fc             	mov    -0x4(%ebp),%eax
     59d:	88 10                	mov    %dl,(%eax)
     59f:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
     5a3:	83 45 f8 01          	addl   $0x1,-0x8(%ebp)
{
  char *dst, *src;
  
  dst = vdst;
  src = vsrc;
  while(n-- > 0)
     5a7:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
     5ab:	0f 9f c0             	setg   %al
     5ae:	83 6d 10 01          	subl   $0x1,0x10(%ebp)
     5b2:	84 c0                	test   %al,%al
     5b4:	75 de                	jne    594 <memmove+0x14>
    *dst++ = *src++;
  return vdst;
     5b6:	8b 45 08             	mov    0x8(%ebp),%eax
}
     5b9:	c9                   	leave  
     5ba:	c3                   	ret    
     5bb:	90                   	nop

000005bc <fork>:
  name: \
    movl $SYS_ ## name, %eax; \
    int $T_SYSCALL; \
    ret

SYSCALL(fork)
     5bc:	b8 01 00 00 00       	mov    $0x1,%eax
     5c1:	cd 40                	int    $0x40
     5c3:	c3                   	ret    

000005c4 <exit>:
SYSCALL(exit)
     5c4:	b8 02 00 00 00       	mov    $0x2,%eax
     5c9:	cd 40                	int    $0x40
     5cb:	c3                   	ret    

000005cc <wait>:
SYSCALL(wait)
     5cc:	b8 03 00 00 00       	mov    $0x3,%eax
     5d1:	cd 40                	int    $0x40
     5d3:	c3                   	ret    

000005d4 <pipe>:
SYSCALL(pipe)
     5d4:	b8 04 00 00 00       	mov    $0x4,%eax
     5d9:	cd 40                	int    $0x40
     5db:	c3                   	ret    

000005dc <read>:
SYSCALL(read)
     5dc:	b8 05 00 00 00       	mov    $0x5,%eax
     5e1:	cd 40                	int    $0x40
     5e3:	c3                   	ret    

000005e4 <write>:
SYSCALL(write)
     5e4:	b8 10 00 00 00       	mov    $0x10,%eax
     5e9:	cd 40                	int    $0x40
     5eb:	c3                   	ret    

000005ec <close>:
SYSCALL(close)
     5ec:	b8 15 00 00 00       	mov    $0x15,%eax
     5f1:	cd 40                	int    $0x40
     5f3:	c3                   	ret    

000005f4 <kill>:
SYSCALL(kill)
     5f4:	b8 06 00 00 00       	mov    $0x6,%eax
     5f9:	cd 40                	int    $0x40
     5fb:	c3                   	ret    

000005fc <exec>:
SYSCALL(exec)
     5fc:	b8 07 00 00 00       	mov    $0x7,%eax
     601:	cd 40                	int    $0x40
     603:	c3                   	ret    

00000604 <open>:
SYSCALL(open)
     604:	b8 0f 00 00 00       	mov    $0xf,%eax
     609:	cd 40                	int    $0x40
     60b:	c3                   	ret    

0000060c <mknod>:
SYSCALL(mknod)
     60c:	b8 11 00 00 00       	mov    $0x11,%eax
     611:	cd 40                	int    $0x40
     613:	c3                   	ret    

00000614 <unlink>:
SYSCALL(unlink)
     614:	b8 12 00 00 00       	mov    $0x12,%eax
     619:	cd 40                	int    $0x40
     61b:	c3                   	ret    

0000061c <fstat>:
SYSCALL(fstat)
     61c:	b8 08 00 00 00       	mov    $0x8,%eax
     621:	cd 40                	int    $0x40
     623:	c3                   	ret    

00000624 <link>:
SYSCALL(link)
     624:	b8 13 00 00 00       	mov    $0x13,%eax
     629:	cd 40                	int    $0x40
     62b:	c3                   	ret    

0000062c <mkdir>:
SYSCALL(mkdir)
     62c:	b8 14 00 00 00       	mov    $0x14,%eax
     631:	cd 40                	int    $0x40
     633:	c3                   	ret    

00000634 <chdir>:
SYSCALL(chdir)
     634:	b8 09 00 00 00       	mov    $0x9,%eax
     639:	cd 40                	int    $0x40
     63b:	c3                   	ret    

0000063c <dup>:
SYSCALL(dup)
     63c:	b8 0a 00 00 00       	mov    $0xa,%eax
     641:	cd 40                	int    $0x40
     643:	c3                   	ret    

00000644 <getpid>:
SYSCALL(getpid)
     644:	b8 0b 00 00 00       	mov    $0xb,%eax
     649:	cd 40                	int    $0x40
     64b:	c3                   	ret    

0000064c <sbrk>:
SYSCALL(sbrk)
     64c:	b8 0c 00 00 00       	mov    $0xc,%eax
     651:	cd 40                	int    $0x40
     653:	c3                   	ret    

00000654 <sleep>:
SYSCALL(sleep)
     654:	b8 0d 00 00 00       	mov    $0xd,%eax
     659:	cd 40                	int    $0x40
     65b:	c3                   	ret    

0000065c <uptime>:
SYSCALL(uptime)
     65c:	b8 0e 00 00 00       	mov    $0xe,%eax
     661:	cd 40                	int    $0x40
     663:	c3                   	ret    

00000664 <signal>:

//our addition
SYSCALL(signal)
     664:	b8 1f 00 00 00       	mov    $0x1f,%eax
     669:	cd 40                	int    $0x40
     66b:	c3                   	ret    

0000066c <sigsend>:
SYSCALL(sigsend)
     66c:	b8 20 00 00 00       	mov    $0x20,%eax
     671:	cd 40                	int    $0x40
     673:	c3                   	ret    

00000674 <alarm>:
SYSCALL(alarm)
     674:	b8 21 00 00 00       	mov    $0x21,%eax
     679:	cd 40                	int    $0x40
     67b:	c3                   	ret    

0000067c <getTicks>:
SYSCALL(getTicks)
     67c:	b8 22 00 00 00       	mov    $0x22,%eax
     681:	cd 40                	int    $0x40
     683:	c3                   	ret    

00000684 <putc>:
#include "stat.h"
#include "user.h"

static void
putc(int fd, char c)
{
     684:	55                   	push   %ebp
     685:	89 e5                	mov    %esp,%ebp
     687:	83 ec 28             	sub    $0x28,%esp
     68a:	8b 45 0c             	mov    0xc(%ebp),%eax
     68d:	88 45 f4             	mov    %al,-0xc(%ebp)
  write(fd, &c, 1);
     690:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
     697:	00 
     698:	8d 45 f4             	lea    -0xc(%ebp),%eax
     69b:	89 44 24 04          	mov    %eax,0x4(%esp)
     69f:	8b 45 08             	mov    0x8(%ebp),%eax
     6a2:	89 04 24             	mov    %eax,(%esp)
     6a5:	e8 3a ff ff ff       	call   5e4 <write>
}
     6aa:	c9                   	leave  
     6ab:	c3                   	ret    

000006ac <printint>:

static void
printint(int fd, int xx, int base, int sgn)
{
     6ac:	55                   	push   %ebp
     6ad:	89 e5                	mov    %esp,%ebp
     6af:	83 ec 48             	sub    $0x48,%esp
  static char digits[] = "0123456789ABCDEF";
  char buf[16];
  int i, neg;
  uint x;

  neg = 0;
     6b2:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
  if(sgn && xx < 0){
     6b9:	83 7d 14 00          	cmpl   $0x0,0x14(%ebp)
     6bd:	74 17                	je     6d6 <printint+0x2a>
     6bf:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
     6c3:	79 11                	jns    6d6 <printint+0x2a>
    neg = 1;
     6c5:	c7 45 f0 01 00 00 00 	movl   $0x1,-0x10(%ebp)
    x = -xx;
     6cc:	8b 45 0c             	mov    0xc(%ebp),%eax
     6cf:	f7 d8                	neg    %eax
     6d1:	89 45 ec             	mov    %eax,-0x14(%ebp)
     6d4:	eb 06                	jmp    6dc <printint+0x30>
  } else {
    x = xx;
     6d6:	8b 45 0c             	mov    0xc(%ebp),%eax
     6d9:	89 45 ec             	mov    %eax,-0x14(%ebp)
  }

  i = 0;
     6dc:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
  do{
    buf[i++] = digits[x % base];
     6e3:	8b 4d 10             	mov    0x10(%ebp),%ecx
     6e6:	8b 45 ec             	mov    -0x14(%ebp),%eax
     6e9:	ba 00 00 00 00       	mov    $0x0,%edx
     6ee:	f7 f1                	div    %ecx
     6f0:	89 d0                	mov    %edx,%eax
     6f2:	0f b6 80 ac 16 00 00 	movzbl 0x16ac(%eax),%eax
     6f9:	8d 4d dc             	lea    -0x24(%ebp),%ecx
     6fc:	8b 55 f4             	mov    -0xc(%ebp),%edx
     6ff:	01 ca                	add    %ecx,%edx
     701:	88 02                	mov    %al,(%edx)
     703:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
  }while((x /= base) != 0);
     707:	8b 55 10             	mov    0x10(%ebp),%edx
     70a:	89 55 d4             	mov    %edx,-0x2c(%ebp)
     70d:	8b 45 ec             	mov    -0x14(%ebp),%eax
     710:	ba 00 00 00 00       	mov    $0x0,%edx
     715:	f7 75 d4             	divl   -0x2c(%ebp)
     718:	89 45 ec             	mov    %eax,-0x14(%ebp)
     71b:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
     71f:	75 c2                	jne    6e3 <printint+0x37>
  if(neg)
     721:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
     725:	74 2e                	je     755 <printint+0xa9>
    buf[i++] = '-';
     727:	8d 55 dc             	lea    -0x24(%ebp),%edx
     72a:	8b 45 f4             	mov    -0xc(%ebp),%eax
     72d:	01 d0                	add    %edx,%eax
     72f:	c6 00 2d             	movb   $0x2d,(%eax)
     732:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)

  while(--i >= 0)
     736:	eb 1d                	jmp    755 <printint+0xa9>
    putc(fd, buf[i]);
     738:	8d 55 dc             	lea    -0x24(%ebp),%edx
     73b:	8b 45 f4             	mov    -0xc(%ebp),%eax
     73e:	01 d0                	add    %edx,%eax
     740:	0f b6 00             	movzbl (%eax),%eax
     743:	0f be c0             	movsbl %al,%eax
     746:	89 44 24 04          	mov    %eax,0x4(%esp)
     74a:	8b 45 08             	mov    0x8(%ebp),%eax
     74d:	89 04 24             	mov    %eax,(%esp)
     750:	e8 2f ff ff ff       	call   684 <putc>
    buf[i++] = digits[x % base];
  }while((x /= base) != 0);
  if(neg)
    buf[i++] = '-';

  while(--i >= 0)
     755:	83 6d f4 01          	subl   $0x1,-0xc(%ebp)
     759:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     75d:	79 d9                	jns    738 <printint+0x8c>
    putc(fd, buf[i]);
}
     75f:	c9                   	leave  
     760:	c3                   	ret    

00000761 <printf>:

// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
     761:	55                   	push   %ebp
     762:	89 e5                	mov    %esp,%ebp
     764:	83 ec 38             	sub    $0x38,%esp
  char *s;
  int c, i, state;
  uint *ap;

  state = 0;
     767:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  ap = (uint*)(void*)&fmt + 1;
     76e:	8d 45 0c             	lea    0xc(%ebp),%eax
     771:	83 c0 04             	add    $0x4,%eax
     774:	89 45 e8             	mov    %eax,-0x18(%ebp)
  for(i = 0; fmt[i]; i++){
     777:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
     77e:	e9 7d 01 00 00       	jmp    900 <printf+0x19f>
    c = fmt[i] & 0xff;
     783:	8b 55 0c             	mov    0xc(%ebp),%edx
     786:	8b 45 f0             	mov    -0x10(%ebp),%eax
     789:	01 d0                	add    %edx,%eax
     78b:	0f b6 00             	movzbl (%eax),%eax
     78e:	0f be c0             	movsbl %al,%eax
     791:	25 ff 00 00 00       	and    $0xff,%eax
     796:	89 45 e4             	mov    %eax,-0x1c(%ebp)
    if(state == 0){
     799:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
     79d:	75 2c                	jne    7cb <printf+0x6a>
      if(c == '%'){
     79f:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
     7a3:	75 0c                	jne    7b1 <printf+0x50>
        state = '%';
     7a5:	c7 45 ec 25 00 00 00 	movl   $0x25,-0x14(%ebp)
     7ac:	e9 4b 01 00 00       	jmp    8fc <printf+0x19b>
      } else {
        putc(fd, c);
     7b1:	8b 45 e4             	mov    -0x1c(%ebp),%eax
     7b4:	0f be c0             	movsbl %al,%eax
     7b7:	89 44 24 04          	mov    %eax,0x4(%esp)
     7bb:	8b 45 08             	mov    0x8(%ebp),%eax
     7be:	89 04 24             	mov    %eax,(%esp)
     7c1:	e8 be fe ff ff       	call   684 <putc>
     7c6:	e9 31 01 00 00       	jmp    8fc <printf+0x19b>
      }
    } else if(state == '%'){
     7cb:	83 7d ec 25          	cmpl   $0x25,-0x14(%ebp)
     7cf:	0f 85 27 01 00 00    	jne    8fc <printf+0x19b>
      if(c == 'd'){
     7d5:	83 7d e4 64          	cmpl   $0x64,-0x1c(%ebp)
     7d9:	75 2d                	jne    808 <printf+0xa7>
        printint(fd, *ap, 10, 1);
     7db:	8b 45 e8             	mov    -0x18(%ebp),%eax
     7de:	8b 00                	mov    (%eax),%eax
     7e0:	c7 44 24 0c 01 00 00 	movl   $0x1,0xc(%esp)
     7e7:	00 
     7e8:	c7 44 24 08 0a 00 00 	movl   $0xa,0x8(%esp)
     7ef:	00 
     7f0:	89 44 24 04          	mov    %eax,0x4(%esp)
     7f4:	8b 45 08             	mov    0x8(%ebp),%eax
     7f7:	89 04 24             	mov    %eax,(%esp)
     7fa:	e8 ad fe ff ff       	call   6ac <printint>
        ap++;
     7ff:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
     803:	e9 ed 00 00 00       	jmp    8f5 <printf+0x194>
      } else if(c == 'x' || c == 'p'){
     808:	83 7d e4 78          	cmpl   $0x78,-0x1c(%ebp)
     80c:	74 06                	je     814 <printf+0xb3>
     80e:	83 7d e4 70          	cmpl   $0x70,-0x1c(%ebp)
     812:	75 2d                	jne    841 <printf+0xe0>
        printint(fd, *ap, 16, 0);
     814:	8b 45 e8             	mov    -0x18(%ebp),%eax
     817:	8b 00                	mov    (%eax),%eax
     819:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
     820:	00 
     821:	c7 44 24 08 10 00 00 	movl   $0x10,0x8(%esp)
     828:	00 
     829:	89 44 24 04          	mov    %eax,0x4(%esp)
     82d:	8b 45 08             	mov    0x8(%ebp),%eax
     830:	89 04 24             	mov    %eax,(%esp)
     833:	e8 74 fe ff ff       	call   6ac <printint>
        ap++;
     838:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
     83c:	e9 b4 00 00 00       	jmp    8f5 <printf+0x194>
      } else if(c == 's'){
     841:	83 7d e4 73          	cmpl   $0x73,-0x1c(%ebp)
     845:	75 46                	jne    88d <printf+0x12c>
        s = (char*)*ap;
     847:	8b 45 e8             	mov    -0x18(%ebp),%eax
     84a:	8b 00                	mov    (%eax),%eax
     84c:	89 45 f4             	mov    %eax,-0xc(%ebp)
        ap++;
     84f:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
        if(s == 0)
     853:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     857:	75 27                	jne    880 <printf+0x11f>
          s = "(null)";
     859:	c7 45 f4 fc 11 00 00 	movl   $0x11fc,-0xc(%ebp)
        while(*s != 0){
     860:	eb 1e                	jmp    880 <printf+0x11f>
          putc(fd, *s);
     862:	8b 45 f4             	mov    -0xc(%ebp),%eax
     865:	0f b6 00             	movzbl (%eax),%eax
     868:	0f be c0             	movsbl %al,%eax
     86b:	89 44 24 04          	mov    %eax,0x4(%esp)
     86f:	8b 45 08             	mov    0x8(%ebp),%eax
     872:	89 04 24             	mov    %eax,(%esp)
     875:	e8 0a fe ff ff       	call   684 <putc>
          s++;
     87a:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     87e:	eb 01                	jmp    881 <printf+0x120>
      } else if(c == 's'){
        s = (char*)*ap;
        ap++;
        if(s == 0)
          s = "(null)";
        while(*s != 0){
     880:	90                   	nop
     881:	8b 45 f4             	mov    -0xc(%ebp),%eax
     884:	0f b6 00             	movzbl (%eax),%eax
     887:	84 c0                	test   %al,%al
     889:	75 d7                	jne    862 <printf+0x101>
     88b:	eb 68                	jmp    8f5 <printf+0x194>
          putc(fd, *s);
          s++;
        }
      } else if(c == 'c'){
     88d:	83 7d e4 63          	cmpl   $0x63,-0x1c(%ebp)
     891:	75 1d                	jne    8b0 <printf+0x14f>
        putc(fd, *ap);
     893:	8b 45 e8             	mov    -0x18(%ebp),%eax
     896:	8b 00                	mov    (%eax),%eax
     898:	0f be c0             	movsbl %al,%eax
     89b:	89 44 24 04          	mov    %eax,0x4(%esp)
     89f:	8b 45 08             	mov    0x8(%ebp),%eax
     8a2:	89 04 24             	mov    %eax,(%esp)
     8a5:	e8 da fd ff ff       	call   684 <putc>
        ap++;
     8aa:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
     8ae:	eb 45                	jmp    8f5 <printf+0x194>
      } else if(c == '%'){
     8b0:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
     8b4:	75 17                	jne    8cd <printf+0x16c>
        putc(fd, c);
     8b6:	8b 45 e4             	mov    -0x1c(%ebp),%eax
     8b9:	0f be c0             	movsbl %al,%eax
     8bc:	89 44 24 04          	mov    %eax,0x4(%esp)
     8c0:	8b 45 08             	mov    0x8(%ebp),%eax
     8c3:	89 04 24             	mov    %eax,(%esp)
     8c6:	e8 b9 fd ff ff       	call   684 <putc>
     8cb:	eb 28                	jmp    8f5 <printf+0x194>
      } else {
        // Unknown % sequence.  Print it to draw attention.
        putc(fd, '%');
     8cd:	c7 44 24 04 25 00 00 	movl   $0x25,0x4(%esp)
     8d4:	00 
     8d5:	8b 45 08             	mov    0x8(%ebp),%eax
     8d8:	89 04 24             	mov    %eax,(%esp)
     8db:	e8 a4 fd ff ff       	call   684 <putc>
        putc(fd, c);
     8e0:	8b 45 e4             	mov    -0x1c(%ebp),%eax
     8e3:	0f be c0             	movsbl %al,%eax
     8e6:	89 44 24 04          	mov    %eax,0x4(%esp)
     8ea:	8b 45 08             	mov    0x8(%ebp),%eax
     8ed:	89 04 24             	mov    %eax,(%esp)
     8f0:	e8 8f fd ff ff       	call   684 <putc>
      }
      state = 0;
     8f5:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  int c, i, state;
  uint *ap;

  state = 0;
  ap = (uint*)(void*)&fmt + 1;
  for(i = 0; fmt[i]; i++){
     8fc:	83 45 f0 01          	addl   $0x1,-0x10(%ebp)
     900:	8b 55 0c             	mov    0xc(%ebp),%edx
     903:	8b 45 f0             	mov    -0x10(%ebp),%eax
     906:	01 d0                	add    %edx,%eax
     908:	0f b6 00             	movzbl (%eax),%eax
     90b:	84 c0                	test   %al,%al
     90d:	0f 85 70 fe ff ff    	jne    783 <printf+0x22>
        putc(fd, c);
      }
      state = 0;
    }
  }
}
     913:	c9                   	leave  
     914:	c3                   	ret    
     915:	66 90                	xchg   %ax,%ax
     917:	90                   	nop

00000918 <free>:
static Header base;
static Header *freep;

void
free(void *ap)
{
     918:	55                   	push   %ebp
     919:	89 e5                	mov    %esp,%ebp
     91b:	83 ec 10             	sub    $0x10,%esp
  Header *bp, *p;

  bp = (Header*)ap - 1;
     91e:	8b 45 08             	mov    0x8(%ebp),%eax
     921:	83 e8 08             	sub    $0x8,%eax
     924:	89 45 f8             	mov    %eax,-0x8(%ebp)
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
     927:	a1 d8 16 00 00       	mov    0x16d8,%eax
     92c:	89 45 fc             	mov    %eax,-0x4(%ebp)
     92f:	eb 24                	jmp    955 <free+0x3d>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
     931:	8b 45 fc             	mov    -0x4(%ebp),%eax
     934:	8b 00                	mov    (%eax),%eax
     936:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     939:	77 12                	ja     94d <free+0x35>
     93b:	8b 45 f8             	mov    -0x8(%ebp),%eax
     93e:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     941:	77 24                	ja     967 <free+0x4f>
     943:	8b 45 fc             	mov    -0x4(%ebp),%eax
     946:	8b 00                	mov    (%eax),%eax
     948:	3b 45 f8             	cmp    -0x8(%ebp),%eax
     94b:	77 1a                	ja     967 <free+0x4f>
free(void *ap)
{
  Header *bp, *p;

  bp = (Header*)ap - 1;
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
     94d:	8b 45 fc             	mov    -0x4(%ebp),%eax
     950:	8b 00                	mov    (%eax),%eax
     952:	89 45 fc             	mov    %eax,-0x4(%ebp)
     955:	8b 45 f8             	mov    -0x8(%ebp),%eax
     958:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     95b:	76 d4                	jbe    931 <free+0x19>
     95d:	8b 45 fc             	mov    -0x4(%ebp),%eax
     960:	8b 00                	mov    (%eax),%eax
     962:	3b 45 f8             	cmp    -0x8(%ebp),%eax
     965:	76 ca                	jbe    931 <free+0x19>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
      break;
  if(bp + bp->s.size == p->s.ptr){
     967:	8b 45 f8             	mov    -0x8(%ebp),%eax
     96a:	8b 40 04             	mov    0x4(%eax),%eax
     96d:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
     974:	8b 45 f8             	mov    -0x8(%ebp),%eax
     977:	01 c2                	add    %eax,%edx
     979:	8b 45 fc             	mov    -0x4(%ebp),%eax
     97c:	8b 00                	mov    (%eax),%eax
     97e:	39 c2                	cmp    %eax,%edx
     980:	75 24                	jne    9a6 <free+0x8e>
    bp->s.size += p->s.ptr->s.size;
     982:	8b 45 f8             	mov    -0x8(%ebp),%eax
     985:	8b 50 04             	mov    0x4(%eax),%edx
     988:	8b 45 fc             	mov    -0x4(%ebp),%eax
     98b:	8b 00                	mov    (%eax),%eax
     98d:	8b 40 04             	mov    0x4(%eax),%eax
     990:	01 c2                	add    %eax,%edx
     992:	8b 45 f8             	mov    -0x8(%ebp),%eax
     995:	89 50 04             	mov    %edx,0x4(%eax)
    bp->s.ptr = p->s.ptr->s.ptr;
     998:	8b 45 fc             	mov    -0x4(%ebp),%eax
     99b:	8b 00                	mov    (%eax),%eax
     99d:	8b 10                	mov    (%eax),%edx
     99f:	8b 45 f8             	mov    -0x8(%ebp),%eax
     9a2:	89 10                	mov    %edx,(%eax)
     9a4:	eb 0a                	jmp    9b0 <free+0x98>
  } else
    bp->s.ptr = p->s.ptr;
     9a6:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9a9:	8b 10                	mov    (%eax),%edx
     9ab:	8b 45 f8             	mov    -0x8(%ebp),%eax
     9ae:	89 10                	mov    %edx,(%eax)
  if(p + p->s.size == bp){
     9b0:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9b3:	8b 40 04             	mov    0x4(%eax),%eax
     9b6:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
     9bd:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9c0:	01 d0                	add    %edx,%eax
     9c2:	3b 45 f8             	cmp    -0x8(%ebp),%eax
     9c5:	75 20                	jne    9e7 <free+0xcf>
    p->s.size += bp->s.size;
     9c7:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9ca:	8b 50 04             	mov    0x4(%eax),%edx
     9cd:	8b 45 f8             	mov    -0x8(%ebp),%eax
     9d0:	8b 40 04             	mov    0x4(%eax),%eax
     9d3:	01 c2                	add    %eax,%edx
     9d5:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9d8:	89 50 04             	mov    %edx,0x4(%eax)
    p->s.ptr = bp->s.ptr;
     9db:	8b 45 f8             	mov    -0x8(%ebp),%eax
     9de:	8b 10                	mov    (%eax),%edx
     9e0:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9e3:	89 10                	mov    %edx,(%eax)
     9e5:	eb 08                	jmp    9ef <free+0xd7>
  } else
    p->s.ptr = bp;
     9e7:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9ea:	8b 55 f8             	mov    -0x8(%ebp),%edx
     9ed:	89 10                	mov    %edx,(%eax)
  freep = p;
     9ef:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9f2:	a3 d8 16 00 00       	mov    %eax,0x16d8
}
     9f7:	c9                   	leave  
     9f8:	c3                   	ret    

000009f9 <morecore>:

static Header*
morecore(uint nu)
{
     9f9:	55                   	push   %ebp
     9fa:	89 e5                	mov    %esp,%ebp
     9fc:	83 ec 28             	sub    $0x28,%esp
  char *p;
  Header *hp;

  if(nu < 4096)
     9ff:	81 7d 08 ff 0f 00 00 	cmpl   $0xfff,0x8(%ebp)
     a06:	77 07                	ja     a0f <morecore+0x16>
    nu = 4096;
     a08:	c7 45 08 00 10 00 00 	movl   $0x1000,0x8(%ebp)
  p = sbrk(nu * sizeof(Header));
     a0f:	8b 45 08             	mov    0x8(%ebp),%eax
     a12:	c1 e0 03             	shl    $0x3,%eax
     a15:	89 04 24             	mov    %eax,(%esp)
     a18:	e8 2f fc ff ff       	call   64c <sbrk>
     a1d:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(p == (char*)-1)
     a20:	83 7d f4 ff          	cmpl   $0xffffffff,-0xc(%ebp)
     a24:	75 07                	jne    a2d <morecore+0x34>
    return 0;
     a26:	b8 00 00 00 00       	mov    $0x0,%eax
     a2b:	eb 22                	jmp    a4f <morecore+0x56>
  hp = (Header*)p;
     a2d:	8b 45 f4             	mov    -0xc(%ebp),%eax
     a30:	89 45 f0             	mov    %eax,-0x10(%ebp)
  hp->s.size = nu;
     a33:	8b 45 f0             	mov    -0x10(%ebp),%eax
     a36:	8b 55 08             	mov    0x8(%ebp),%edx
     a39:	89 50 04             	mov    %edx,0x4(%eax)
  free((void*)(hp + 1));
     a3c:	8b 45 f0             	mov    -0x10(%ebp),%eax
     a3f:	83 c0 08             	add    $0x8,%eax
     a42:	89 04 24             	mov    %eax,(%esp)
     a45:	e8 ce fe ff ff       	call   918 <free>
  return freep;
     a4a:	a1 d8 16 00 00       	mov    0x16d8,%eax
}
     a4f:	c9                   	leave  
     a50:	c3                   	ret    

00000a51 <malloc>:

void*
malloc(uint nbytes)
{
     a51:	55                   	push   %ebp
     a52:	89 e5                	mov    %esp,%ebp
     a54:	83 ec 28             	sub    $0x28,%esp
  Header *p, *prevp;
  uint nunits;

  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
     a57:	8b 45 08             	mov    0x8(%ebp),%eax
     a5a:	83 c0 07             	add    $0x7,%eax
     a5d:	c1 e8 03             	shr    $0x3,%eax
     a60:	83 c0 01             	add    $0x1,%eax
     a63:	89 45 ec             	mov    %eax,-0x14(%ebp)
  if((prevp = freep) == 0){
     a66:	a1 d8 16 00 00       	mov    0x16d8,%eax
     a6b:	89 45 f0             	mov    %eax,-0x10(%ebp)
     a6e:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
     a72:	75 23                	jne    a97 <malloc+0x46>
    base.s.ptr = freep = prevp = &base;
     a74:	c7 45 f0 d0 16 00 00 	movl   $0x16d0,-0x10(%ebp)
     a7b:	8b 45 f0             	mov    -0x10(%ebp),%eax
     a7e:	a3 d8 16 00 00       	mov    %eax,0x16d8
     a83:	a1 d8 16 00 00       	mov    0x16d8,%eax
     a88:	a3 d0 16 00 00       	mov    %eax,0x16d0
    base.s.size = 0;
     a8d:	c7 05 d4 16 00 00 00 	movl   $0x0,0x16d4
     a94:	00 00 00 
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
     a97:	8b 45 f0             	mov    -0x10(%ebp),%eax
     a9a:	8b 00                	mov    (%eax),%eax
     a9c:	89 45 f4             	mov    %eax,-0xc(%ebp)
    if(p->s.size >= nunits){
     a9f:	8b 45 f4             	mov    -0xc(%ebp),%eax
     aa2:	8b 40 04             	mov    0x4(%eax),%eax
     aa5:	3b 45 ec             	cmp    -0x14(%ebp),%eax
     aa8:	72 4d                	jb     af7 <malloc+0xa6>
      if(p->s.size == nunits)
     aaa:	8b 45 f4             	mov    -0xc(%ebp),%eax
     aad:	8b 40 04             	mov    0x4(%eax),%eax
     ab0:	3b 45 ec             	cmp    -0x14(%ebp),%eax
     ab3:	75 0c                	jne    ac1 <malloc+0x70>
        prevp->s.ptr = p->s.ptr;
     ab5:	8b 45 f4             	mov    -0xc(%ebp),%eax
     ab8:	8b 10                	mov    (%eax),%edx
     aba:	8b 45 f0             	mov    -0x10(%ebp),%eax
     abd:	89 10                	mov    %edx,(%eax)
     abf:	eb 26                	jmp    ae7 <malloc+0x96>
      else {
        p->s.size -= nunits;
     ac1:	8b 45 f4             	mov    -0xc(%ebp),%eax
     ac4:	8b 40 04             	mov    0x4(%eax),%eax
     ac7:	89 c2                	mov    %eax,%edx
     ac9:	2b 55 ec             	sub    -0x14(%ebp),%edx
     acc:	8b 45 f4             	mov    -0xc(%ebp),%eax
     acf:	89 50 04             	mov    %edx,0x4(%eax)
        p += p->s.size;
     ad2:	8b 45 f4             	mov    -0xc(%ebp),%eax
     ad5:	8b 40 04             	mov    0x4(%eax),%eax
     ad8:	c1 e0 03             	shl    $0x3,%eax
     adb:	01 45 f4             	add    %eax,-0xc(%ebp)
        p->s.size = nunits;
     ade:	8b 45 f4             	mov    -0xc(%ebp),%eax
     ae1:	8b 55 ec             	mov    -0x14(%ebp),%edx
     ae4:	89 50 04             	mov    %edx,0x4(%eax)
      }
      freep = prevp;
     ae7:	8b 45 f0             	mov    -0x10(%ebp),%eax
     aea:	a3 d8 16 00 00       	mov    %eax,0x16d8
      return (void*)(p + 1);
     aef:	8b 45 f4             	mov    -0xc(%ebp),%eax
     af2:	83 c0 08             	add    $0x8,%eax
     af5:	eb 38                	jmp    b2f <malloc+0xde>
    }
    if(p == freep)
     af7:	a1 d8 16 00 00       	mov    0x16d8,%eax
     afc:	39 45 f4             	cmp    %eax,-0xc(%ebp)
     aff:	75 1b                	jne    b1c <malloc+0xcb>
      if((p = morecore(nunits)) == 0)
     b01:	8b 45 ec             	mov    -0x14(%ebp),%eax
     b04:	89 04 24             	mov    %eax,(%esp)
     b07:	e8 ed fe ff ff       	call   9f9 <morecore>
     b0c:	89 45 f4             	mov    %eax,-0xc(%ebp)
     b0f:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     b13:	75 07                	jne    b1c <malloc+0xcb>
        return 0;
     b15:	b8 00 00 00 00       	mov    $0x0,%eax
     b1a:	eb 13                	jmp    b2f <malloc+0xde>
  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
  if((prevp = freep) == 0){
    base.s.ptr = freep = prevp = &base;
    base.s.size = 0;
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
     b1c:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b1f:	89 45 f0             	mov    %eax,-0x10(%ebp)
     b22:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b25:	8b 00                	mov    (%eax),%eax
     b27:	89 45 f4             	mov    %eax,-0xc(%ebp)
      return (void*)(p + 1);
    }
    if(p == freep)
      if((p = morecore(nunits)) == 0)
        return 0;
  }
     b2a:	e9 70 ff ff ff       	jmp    a9f <malloc+0x4e>
}
     b2f:	c9                   	leave  
     b30:	c3                   	ret    
     b31:	66 90                	xchg   %ax,%ax
     b33:	90                   	nop

00000b34 <uthread_init>:
int c_thread = 0;

// task 2.2

void uthread_init()
{
     b34:	55                   	push   %ebp
     b35:	89 e5                	mov    %esp,%ebp
     b37:	83 ec 28             	sub    $0x28,%esp

	int i;
	ttable[0].tid = 0;
     b3a:	c7 05 e0 16 00 00 00 	movl   $0x0,0x16e0
     b41:	00 00 00 
	STORE_ESP(ttable[0].esp);
     b44:	89 e0                	mov    %esp,%eax
     b46:	a3 e4 16 00 00       	mov    %eax,0x16e4
	STORE_EBP(ttable[0].ebp);
     b4b:	89 e8                	mov    %ebp,%eax
     b4d:	a3 e8 16 00 00       	mov    %eax,0x16e8
	ttable[0].state = T_RUNNING;
     b52:	c7 05 f0 16 00 00 01 	movl   $0x1,0x16f0
     b59:	00 00 00 
	ttable[0].wait_num = 0;
     b5c:	c7 05 f4 17 00 00 00 	movl   $0x0,0x17f4
     b63:	00 00 00 
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
     b66:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
     b6d:	eb 2c                	jmp    b9b <uthread_init+0x67>
	{
		ttable[i].tid = i;
     b6f:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b72:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     b78:	8d 90 e0 16 00 00    	lea    0x16e0(%eax),%edx
     b7e:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b81:	89 02                	mov    %eax,(%edx)
		ttable[i].state = T_FREE;
     b83:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b86:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     b8c:	05 f0 16 00 00       	add    $0x16f0,%eax
     b91:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	STORE_ESP(ttable[0].esp);
	STORE_EBP(ttable[0].ebp);
	ttable[0].state = T_RUNNING;
	ttable[0].wait_num = 0;
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
     b97:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     b9b:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     b9f:	7e ce                	jle    b6f <uthread_init+0x3b>
	{
		ttable[i].tid = i;
		ttable[i].state = T_FREE;
	}
	signal(SIGALRM, uthread_yield);
     ba1:	c7 44 24 04 27 0e 00 	movl   $0xe27,0x4(%esp)
     ba8:	00 
     ba9:	c7 04 24 0e 00 00 00 	movl   $0xe,(%esp)
     bb0:	e8 af fa ff ff       	call   664 <signal>
	alarm(THREAD_QUANTA);
     bb5:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
     bbc:	e8 b3 fa ff ff       	call   674 <alarm>
}
     bc1:	c9                   	leave  
     bc2:	c3                   	ret    

00000bc3 <uthread_create>:

// task 2.3

int uthread_create(void (*start_func)(void *), void*arg)
{
     bc3:	55                   	push   %ebp
     bc4:	89 e5                	mov    %esp,%ebp
     bc6:	83 ec 28             	sub    $0x28,%esp
	int i;
	int ticks;
	asm("pusha");
     bc9:	60                   	pusha  
	ticks = getTicks();
     bca:	e8 ad fa ff ff       	call   67c <getTicks>
     bcf:	89 45 f0             	mov    %eax,-0x10(%ebp)
	alarm(0);
     bd2:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     bd9:	e8 96 fa ff ff       	call   674 <alarm>
	asm("popa");
     bde:	61                   	popa   
	for (i = 0; i < MAX_THREAD; i++)
     bdf:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
     be6:	e9 02 01 00 00       	jmp    ced <uthread_create+0x12a>
	{
		if (ttable[i].state == T_FREE)
     beb:	8b 45 f4             	mov    -0xc(%ebp),%eax
     bee:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     bf4:	05 f0 16 00 00       	add    $0x16f0,%eax
     bf9:	8b 00                	mov    (%eax),%eax
     bfb:	85 c0                	test   %eax,%eax
     bfd:	0f 85 e6 00 00 00    	jne    ce9 <uthread_create+0x126>
		{	
			//allocate a stack for the new thread
			if ((ttable[i].stack = malloc(STACK_SIZE)) < 0)
     c03:	c7 04 24 00 10 00 00 	movl   $0x1000,(%esp)
     c0a:	e8 42 fe ff ff       	call   a51 <malloc>
     c0f:	8b 55 f4             	mov    -0xc(%ebp),%edx
     c12:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     c18:	81 c2 e0 16 00 00    	add    $0x16e0,%edx
     c1e:	89 42 0c             	mov    %eax,0xc(%edx)
			{
				alarm(ticks);
				return -1;
			}
			LOAD_ESP(ttable[i].stack + STACK_SIZE);
     c21:	8b 45 f4             	mov    -0xc(%ebp),%eax
     c24:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     c2a:	05 e0 16 00 00       	add    $0x16e0,%eax
     c2f:	8b 40 0c             	mov    0xc(%eax),%eax
     c32:	05 00 10 00 00       	add    $0x1000,%eax
     c37:	89 c4                	mov    %eax,%esp
			PUSH(arg);
     c39:	8b 45 0c             	mov    0xc(%ebp),%eax
     c3c:	89 c7                	mov    %eax,%edi
     c3e:	57                   	push   %edi
			PUSH(uthread_exit);
     c3f:	b8 ad 0e 00 00       	mov    $0xead,%eax
     c44:	89 c7                	mov    %eax,%edi
     c46:	57                   	push   %edi
			PUSH(start_func);
     c47:	8b 45 08             	mov    0x8(%ebp),%eax
     c4a:	89 c7                	mov    %eax,%edi
     c4c:	57                   	push   %edi
			//added for the first "pop ebp"
			PUSH(0);
     c4d:	b8 00 00 00 00       	mov    $0x0,%eax
     c52:	89 c7                	mov    %eax,%edi
     c54:	57                   	push   %edi
			STORE_ESP(ttable[i].ebp);
     c55:	89 e0                	mov    %esp,%eax
     c57:	8b 55 f4             	mov    -0xc(%ebp),%edx
     c5a:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     c60:	81 c2 e0 16 00 00    	add    $0x16e0,%edx
     c66:	89 42 08             	mov    %eax,0x8(%edx)
			ttable[i].esp = ttable[i].ebp;
     c69:	8b 45 f4             	mov    -0xc(%ebp),%eax
     c6c:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     c72:	05 e0 16 00 00       	add    $0x16e0,%eax
     c77:	8b 40 08             	mov    0x8(%eax),%eax
     c7a:	8b 55 f4             	mov    -0xc(%ebp),%edx
     c7d:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     c83:	81 c2 e0 16 00 00    	add    $0x16e0,%edx
     c89:	89 42 04             	mov    %eax,0x4(%edx)
			//set esp to current thread's esp
			LOAD_ESP(ttable[c_thread].esp);
     c8c:	a1 dc 16 00 00       	mov    0x16dc,%eax
     c91:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     c97:	05 e0 16 00 00       	add    $0x16e0,%eax
     c9c:	8b 40 04             	mov    0x4(%eax),%eax
     c9f:	89 c4                	mov    %eax,%esp
			ttable[i].state = T_RUNNABLE;
     ca1:	8b 45 f4             	mov    -0xc(%ebp),%eax
     ca4:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     caa:	05 f0 16 00 00       	add    $0x16f0,%eax
     caf:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
			ttable[i].wait_num = 0;
     cb5:	8b 45 f4             	mov    -0xc(%ebp),%eax
     cb8:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     cbe:	05 f0 17 00 00       	add    $0x17f0,%eax
     cc3:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
			asm("pusha");
     cca:	60                   	pusha  
			alarm(ticks);
     ccb:	8b 45 f0             	mov    -0x10(%ebp),%eax
     cce:	89 04 24             	mov    %eax,(%esp)
     cd1:	e8 9e f9 ff ff       	call   674 <alarm>
			asm("popa");
     cd6:	61                   	popa   
			return ttable[i].tid;
     cd7:	8b 45 f4             	mov    -0xc(%ebp),%eax
     cda:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     ce0:	05 e0 16 00 00       	add    $0x16e0,%eax
     ce5:	8b 00                	mov    (%eax),%eax
     ce7:	eb 1e                	jmp    d07 <uthread_create+0x144>
	int ticks;
	asm("pusha");
	ticks = getTicks();
	alarm(0);
	asm("popa");
	for (i = 0; i < MAX_THREAD; i++)
     ce9:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     ced:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     cf1:	0f 8e f4 fe ff ff    	jle    beb <uthread_create+0x28>
			asm("popa");
			return ttable[i].tid;
			
		}
	}
	alarm(ticks);
     cf7:	8b 45 f0             	mov    -0x10(%ebp),%eax
     cfa:	89 04 24             	mov    %eax,(%esp)
     cfd:	e8 72 f9 ff ff       	call   674 <alarm>
	//failed - no free thread to use
	return -1;
     d02:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
     d07:	c9                   	leave  
     d08:	c3                   	ret    

00000d09 <safe_exit>:

// task 2.4


void safe_exit()
{
     d09:	55                   	push   %ebp
     d0a:	89 e5                	mov    %esp,%ebp
     d0c:	83 ec 28             	sub    $0x28,%esp
     d0f:	eb 01                	jmp    d12 <safe_exit+0x9>
			}
		}
		if (tid == MAX_THREAD){
			exit();
		}
	}
     d11:	90                   	nop
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
     d12:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
     d19:	eb 25                	jmp    d40 <safe_exit+0x37>
		{
			if (ttable[tid].state != T_FREE){
     d1b:	8b 45 f4             	mov    -0xc(%ebp),%eax
     d1e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     d24:	05 f0 16 00 00       	add    $0x16f0,%eax
     d29:	8b 00                	mov    (%eax),%eax
     d2b:	85 c0                	test   %eax,%eax
     d2d:	74 0d                	je     d3c <safe_exit+0x33>
				uthread_join(tid);
     d2f:	8b 45 f4             	mov    -0xc(%ebp),%eax
     d32:	89 04 24             	mov    %eax,(%esp)
     d35:	e8 1d 02 00 00       	call   f57 <uthread_join>
				break;
     d3a:	eb 0a                	jmp    d46 <safe_exit+0x3d>
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
     d3c:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     d40:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     d44:	7e d5                	jle    d1b <safe_exit+0x12>
			if (ttable[tid].state != T_FREE){
				uthread_join(tid);
				break;
			}
		}
		if (tid == MAX_THREAD){
     d46:	83 7d f4 40          	cmpl   $0x40,-0xc(%ebp)
     d4a:	75 c5                	jne    d11 <safe_exit+0x8>
			exit();
     d4c:	e8 73 f8 ff ff       	call   5c4 <exit>

00000d51 <uthread_switch>:
		}
	}
}

void uthread_switch()
{
     d51:	55                   	push   %ebp
     d52:	89 e5                	mov    %esp,%ebp
     d54:	83 ec 28             	sub    $0x28,%esp
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;
     d57:	a1 dc 16 00 00       	mov    0x16dc,%eax
     d5c:	8d 50 01             	lea    0x1(%eax),%edx
     d5f:	89 d0                	mov    %edx,%eax
     d61:	c1 f8 1f             	sar    $0x1f,%eax
     d64:	c1 e8 1a             	shr    $0x1a,%eax
     d67:	01 c2                	add    %eax,%edx
     d69:	83 e2 3f             	and    $0x3f,%edx
     d6c:	89 d1                	mov    %edx,%ecx
     d6e:	29 c1                	sub    %eax,%ecx
     d70:	89 c8                	mov    %ecx,%eax
     d72:	89 45 f0             	mov    %eax,-0x10(%ebp)

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
     d75:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
     d7c:	eb 20                	jmp    d9e <uthread_switch+0x4d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
     d7e:	8b 45 f0             	mov    -0x10(%ebp),%eax
     d81:	8d 50 01             	lea    0x1(%eax),%edx
     d84:	89 d0                	mov    %edx,%eax
     d86:	c1 f8 1f             	sar    $0x1f,%eax
     d89:	c1 e8 1a             	shr    $0x1a,%eax
     d8c:	01 c2                	add    %eax,%edx
     d8e:	83 e2 3f             	and    $0x3f,%edx
     d91:	89 d1                	mov    %edx,%ecx
     d93:	29 c1                	sub    %eax,%ecx
     d95:	89 c8                	mov    %ecx,%eax
     d97:	89 45 f0             	mov    %eax,-0x10(%ebp)
{
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
     d9a:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     d9e:	8b 45 f0             	mov    -0x10(%ebp),%eax
     da1:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     da7:	05 f0 16 00 00       	add    $0x16f0,%eax
     dac:	8b 00                	mov    (%eax),%eax
     dae:	83 f8 02             	cmp    $0x2,%eax
     db1:	74 06                	je     db9 <uthread_switch+0x68>
     db3:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     db7:	7e c5                	jle    d7e <uthread_switch+0x2d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
	}
	STORE_ESP(ttable[c_thread].esp);
     db9:	8b 15 dc 16 00 00    	mov    0x16dc,%edx
     dbf:	89 e0                	mov    %esp,%eax
     dc1:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     dc7:	81 c2 e0 16 00 00    	add    $0x16e0,%edx
     dcd:	89 42 04             	mov    %eax,0x4(%edx)
	STORE_EBP(ttable[c_thread].ebp);
     dd0:	8b 15 dc 16 00 00    	mov    0x16dc,%edx
     dd6:	89 e8                	mov    %ebp,%eax
     dd8:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     dde:	81 c2 e0 16 00 00    	add    $0x16e0,%edx
     de4:	89 42 08             	mov    %eax,0x8(%edx)
	c_thread = n_thread;
     de7:	8b 45 f0             	mov    -0x10(%ebp),%eax
     dea:	a3 dc 16 00 00       	mov    %eax,0x16dc
	LOAD_EBP(ttable[c_thread].ebp);
     def:	a1 dc 16 00 00       	mov    0x16dc,%eax
     df4:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     dfa:	05 e0 16 00 00       	add    $0x16e0,%eax
     dff:	8b 40 08             	mov    0x8(%eax),%eax
     e02:	89 c5                	mov    %eax,%ebp
	LOAD_ESP(ttable[c_thread].esp);
     e04:	a1 dc 16 00 00       	mov    0x16dc,%eax
     e09:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     e0f:	05 e0 16 00 00       	add    $0x16e0,%eax
     e14:	8b 40 04             	mov    0x4(%eax),%eax
     e17:	89 c4                	mov    %eax,%esp
	alarm(THREAD_QUANTA);
     e19:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
     e20:	e8 4f f8 ff ff       	call   674 <alarm>
}
     e25:	c9                   	leave  
     e26:	c3                   	ret    

00000e27 <uthread_yield>:

void uthread_yield()
{
     e27:	55                   	push   %ebp
     e28:	89 e5                	mov    %esp,%ebp
     e2a:	83 ec 18             	sub    $0x18,%esp
	//store registers on stack
	asm("pusha");
     e2d:	60                   	pusha  
	alarm(0);
     e2e:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     e35:	e8 3a f8 ff ff       	call   674 <alarm>
	ttable[c_thread].state = T_RUNNABLE;
     e3a:	a1 dc 16 00 00       	mov    0x16dc,%eax
     e3f:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     e45:	05 f0 16 00 00       	add    $0x16f0,%eax
     e4a:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
	//change current thread
	uthread_switch();
     e50:	e8 fc fe ff ff       	call   d51 <uthread_switch>
	asm("popa");
     e55:	61                   	popa   
}
     e56:	c9                   	leave  
     e57:	c3                   	ret    

00000e58 <uthread_awake>:

// task 2.5

void uthread_awake()
{
     e58:	55                   	push   %ebp
     e59:	89 e5                	mov    %esp,%ebp
     e5b:	83 ec 10             	sub    $0x10,%esp
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
     e5e:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
     e65:	eb 2c                	jmp    e93 <uthread_awake+0x3b>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
     e67:	a1 dc 16 00 00       	mov    0x16dc,%eax
     e6c:	6b d0 46             	imul   $0x46,%eax,%edx
     e6f:	8b 45 fc             	mov    -0x4(%ebp),%eax
     e72:	01 d0                	add    %edx,%eax
     e74:	83 c0 04             	add    $0x4,%eax
     e77:	8b 04 85 e4 16 00 00 	mov    0x16e4(,%eax,4),%eax
     e7e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     e84:	05 f0 16 00 00       	add    $0x16f0,%eax
     e89:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
// task 2.5

void uthread_awake()
{
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
     e8f:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
     e93:	a1 dc 16 00 00       	mov    0x16dc,%eax
     e98:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     e9e:	05 f0 17 00 00       	add    $0x17f0,%eax
     ea3:	8b 40 04             	mov    0x4(%eax),%eax
     ea6:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     ea9:	7f bc                	jg     e67 <uthread_awake+0xf>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
}
     eab:	c9                   	leave  
     eac:	c3                   	ret    

00000ead <uthread_exit>:

void uthread_exit()
{
     ead:	55                   	push   %ebp
     eae:	89 e5                	mov    %esp,%ebp
     eb0:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
     eb3:	60                   	pusha  
	alarm(0);
     eb4:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     ebb:	e8 b4 f7 ff ff       	call   674 <alarm>
	asm("popa");
     ec0:	61                   	popa   
	ttable[c_thread].state = T_FREE;
     ec1:	a1 dc 16 00 00       	mov    0x16dc,%eax
     ec6:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     ecc:	05 f0 16 00 00       	add    $0x16f0,%eax
     ed1:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	if (ttable[c_thread].tid != 0)
     ed7:	a1 dc 16 00 00       	mov    0x16dc,%eax
     edc:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     ee2:	05 e0 16 00 00       	add    $0x16e0,%eax
     ee7:	8b 00                	mov    (%eax),%eax
     ee9:	85 c0                	test   %eax,%eax
     eeb:	74 1d                	je     f0a <uthread_exit+0x5d>
		free(ttable[c_thread].stack);
     eed:	a1 dc 16 00 00       	mov    0x16dc,%eax
     ef2:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     ef8:	05 e0 16 00 00       	add    $0x16e0,%eax
     efd:	8b 40 0c             	mov    0xc(%eax),%eax
     f00:	89 04 24             	mov    %eax,(%esp)
     f03:	e8 10 fa ff ff       	call   918 <free>
     f08:	eb 05                	jmp    f0f <uthread_exit+0x62>
	else
		safe_exit();
     f0a:	e8 fa fd ff ff       	call   d09 <safe_exit>
	uthread_awake();
     f0f:	e8 44 ff ff ff       	call   e58 <uthread_awake>
	uthread_switch();
     f14:	e8 38 fe ff ff       	call   d51 <uthread_switch>
	asm("popa");
     f19:	61                   	popa   
}
     f1a:	c9                   	leave  
     f1b:	c3                   	ret    

00000f1c <uthread_self>:

// task 2.6

int uthread_self()
{
     f1c:	55                   	push   %ebp
     f1d:	89 e5                	mov    %esp,%ebp
	return c_thread;
     f1f:	a1 dc 16 00 00       	mov    0x16dc,%eax
}
     f24:	5d                   	pop    %ebp
     f25:	c3                   	ret    

00000f26 <uthread_sleep>:

// task 2.7

void uthread_sleep()
{
     f26:	55                   	push   %ebp
     f27:	89 e5                	mov    %esp,%ebp
     f29:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
     f2c:	60                   	pusha  
	alarm(0);
     f2d:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     f34:	e8 3b f7 ff ff       	call   674 <alarm>
	ttable[c_thread].state = T_SLEEPING;
     f39:	a1 dc 16 00 00       	mov    0x16dc,%eax
     f3e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     f44:	05 f0 16 00 00       	add    $0x16f0,%eax
     f49:	c7 00 03 00 00 00    	movl   $0x3,(%eax)
	uthread_switch();
     f4f:	e8 fd fd ff ff       	call   d51 <uthread_switch>
	asm("popa");
     f54:	61                   	popa   
}
     f55:	c9                   	leave  
     f56:	c3                   	ret    

00000f57 <uthread_join>:

int uthread_join(int tid)
{
     f57:	55                   	push   %ebp
     f58:	89 e5                	mov    %esp,%ebp
     f5a:	53                   	push   %ebx
     f5b:	83 ec 24             	sub    $0x24,%esp

	int ticks;
	asm("pusha");
     f5e:	60                   	pusha  
	ticks = getTicks();
     f5f:	e8 18 f7 ff ff       	call   67c <getTicks>
     f64:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
     f67:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     f6e:	e8 01 f7 ff ff       	call   674 <alarm>
	asm("popa");
     f73:	61                   	popa   
	if (ttable[tid].state != T_FREE)
     f74:	8b 45 08             	mov    0x8(%ebp),%eax
     f77:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     f7d:	05 f0 16 00 00       	add    $0x16f0,%eax
     f82:	8b 00                	mov    (%eax),%eax
     f84:	85 c0                	test   %eax,%eax
     f86:	74 5e                	je     fe6 <uthread_join+0x8f>
	{
		//adding current thread to tid waiting list and going to sleep.
		ttable[tid].waiting[ttable[tid].wait_num++] = ttable[c_thread].tid;
     f88:	8b 45 08             	mov    0x8(%ebp),%eax
     f8b:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     f91:	05 10 01 00 00       	add    $0x110,%eax
     f96:	05 e0 16 00 00       	add    $0x16e0,%eax
     f9b:	8d 48 04             	lea    0x4(%eax),%ecx
     f9e:	8b 45 08             	mov    0x8(%ebp),%eax
     fa1:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     fa7:	05 f0 17 00 00       	add    $0x17f0,%eax
     fac:	8b 40 04             	mov    0x4(%eax),%eax
     faf:	8b 15 dc 16 00 00    	mov    0x16dc,%edx
     fb5:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     fbb:	81 c2 e0 16 00 00    	add    $0x16e0,%edx
     fc1:	8b 12                	mov    (%edx),%edx
     fc3:	8b 5d 08             	mov    0x8(%ebp),%ebx
     fc6:	6b db 46             	imul   $0x46,%ebx,%ebx
     fc9:	01 c3                	add    %eax,%ebx
     fcb:	83 c3 04             	add    $0x4,%ebx
     fce:	89 14 9d e4 16 00 00 	mov    %edx,0x16e4(,%ebx,4)
     fd5:	83 c0 01             	add    $0x1,%eax
     fd8:	89 01                	mov    %eax,(%ecx)
		uthread_sleep();
     fda:	e8 47 ff ff ff       	call   f26 <uthread_sleep>
		return 0;
     fdf:	b8 00 00 00 00       	mov    $0x0,%eax
     fe4:	eb 12                	jmp    ff8 <uthread_join+0xa1>
	}
	asm("pusha");
     fe6:	60                   	pusha  
	alarm(ticks);
     fe7:	8b 45 f4             	mov    -0xc(%ebp),%eax
     fea:	89 04 24             	mov    %eax,(%esp)
     fed:	e8 82 f6 ff ff       	call   674 <alarm>
	asm("popa");
     ff2:	61                   	popa   
	return -1;
     ff3:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
     ff8:	83 c4 24             	add    $0x24,%esp
     ffb:	5b                   	pop    %ebx
     ffc:	5d                   	pop    %ebp
     ffd:	c3                   	ret    

00000ffe <queue_init>:

void queue_init(struct tqueue *q)
{
     ffe:	55                   	push   %ebp
     fff:	89 e5                	mov    %esp,%ebp
	q->head = 0;
    1001:	8b 45 08             	mov    0x8(%ebp),%eax
    1004:	c7 80 00 01 00 00 00 	movl   $0x0,0x100(%eax)
    100b:	00 00 00 
	q->tail = 0;
    100e:	8b 45 08             	mov    0x8(%ebp),%eax
    1011:	c7 80 04 01 00 00 00 	movl   $0x0,0x104(%eax)
    1018:	00 00 00 
}
    101b:	5d                   	pop    %ebp
    101c:	c3                   	ret    

0000101d <dequeue>:

struct uthread* dequeue(struct binary_semaphore* semaphore)
{
    101d:	55                   	push   %ebp
    101e:	89 e5                	mov    %esp,%ebp
    1020:	57                   	push   %edi
    1021:	56                   	push   %esi
    1022:	53                   	push   %ebx
	if (semaphore->queue->head == semaphore->queue->tail)
    1023:	8b 45 08             	mov    0x8(%ebp),%eax
    1026:	8b 00                	mov    (%eax),%eax
    1028:	8b 90 00 01 00 00    	mov    0x100(%eax),%edx
    102e:	8b 45 08             	mov    0x8(%ebp),%eax
    1031:	8b 00                	mov    (%eax),%eax
    1033:	8b 80 04 01 00 00    	mov    0x104(%eax),%eax
    1039:	39 c2                	cmp    %eax,%edx
    103b:	75 07                	jne    1044 <dequeue+0x27>
		return 0;
    103d:	b9 00 00 00 00       	mov    $0x0,%ecx
    1042:	eb 31                	jmp    1075 <dequeue+0x58>
	return semaphore->queue->uthreads[semaphore->queue->tail++ % MAX_THREAD];
    1044:	8b 45 08             	mov    0x8(%ebp),%eax
    1047:	8b 18                	mov    (%eax),%ebx
    1049:	8b 45 08             	mov    0x8(%ebp),%eax
    104c:	8b 10                	mov    (%eax),%edx
    104e:	8b 82 04 01 00 00    	mov    0x104(%edx),%eax
    1054:	89 c1                	mov    %eax,%ecx
    1056:	c1 f9 1f             	sar    $0x1f,%ecx
    1059:	c1 e9 1a             	shr    $0x1a,%ecx
    105c:	8d 34 08             	lea    (%eax,%ecx,1),%esi
    105f:	83 e6 3f             	and    $0x3f,%esi
    1062:	89 f7                	mov    %esi,%edi
    1064:	29 cf                	sub    %ecx,%edi
    1066:	89 f9                	mov    %edi,%ecx
    1068:	8b 0c 8b             	mov    (%ebx,%ecx,4),%ecx
    106b:	83 c0 01             	add    $0x1,%eax
    106e:	89 82 04 01 00 00    	mov    %eax,0x104(%edx)
    1074:	90                   	nop
    1075:	89 c8                	mov    %ecx,%eax
}
    1077:	5b                   	pop    %ebx
    1078:	5e                   	pop    %esi
    1079:	5f                   	pop    %edi
    107a:	5d                   	pop    %ebp
    107b:	c3                   	ret    

0000107c <enqueue>:

void enqueue(struct binary_semaphore* semaphore)
{
    107c:	55                   	push   %ebp
    107d:	89 e5                	mov    %esp,%ebp
    107f:	57                   	push   %edi
    1080:	56                   	push   %esi
    1081:	53                   	push   %ebx
	semaphore->queue->uthreads[semaphore->queue->head++ % MAX_THREAD] = &ttable[c_thread];
    1082:	8b 45 08             	mov    0x8(%ebp),%eax
    1085:	8b 18                	mov    (%eax),%ebx
    1087:	8b 45 08             	mov    0x8(%ebp),%eax
    108a:	8b 10                	mov    (%eax),%edx
    108c:	8b 82 00 01 00 00    	mov    0x100(%edx),%eax
    1092:	89 c1                	mov    %eax,%ecx
    1094:	c1 f9 1f             	sar    $0x1f,%ecx
    1097:	c1 e9 1a             	shr    $0x1a,%ecx
    109a:	8d 34 08             	lea    (%eax,%ecx,1),%esi
    109d:	83 e6 3f             	and    $0x3f,%esi
    10a0:	89 f7                	mov    %esi,%edi
    10a2:	29 cf                	sub    %ecx,%edi
    10a4:	89 f9                	mov    %edi,%ecx
    10a6:	8b 35 dc 16 00 00    	mov    0x16dc,%esi
    10ac:	69 f6 18 01 00 00    	imul   $0x118,%esi,%esi
    10b2:	81 c6 e0 16 00 00    	add    $0x16e0,%esi
    10b8:	89 34 8b             	mov    %esi,(%ebx,%ecx,4)
    10bb:	83 c0 01             	add    $0x1,%eax
    10be:	89 82 00 01 00 00    	mov    %eax,0x100(%edx)
}
    10c4:	5b                   	pop    %ebx
    10c5:	5e                   	pop    %esi
    10c6:	5f                   	pop    %edi
    10c7:	5d                   	pop    %ebp
    10c8:	c3                   	ret    

000010c9 <binary_semaphore_init>:

void binary_semaphore_init(struct binary_semaphore* semaphore, int value)
{
    10c9:	55                   	push   %ebp
    10ca:	89 e5                	mov    %esp,%ebp
    10cc:	83 ec 18             	sub    $0x18,%esp
	semaphore->queue = malloc(sizeof(struct tqueue));
    10cf:	c7 04 24 08 01 00 00 	movl   $0x108,(%esp)
    10d6:	e8 76 f9 ff ff       	call   a51 <malloc>
    10db:	8b 55 08             	mov    0x8(%ebp),%edx
    10de:	89 02                	mov    %eax,(%edx)
	if (!value)
    10e0:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
    10e4:	75 0c                	jne    10f2 <binary_semaphore_init+0x29>
		semaphore->state = S_LOCKED;
    10e6:	8b 45 08             	mov    0x8(%ebp),%eax
    10e9:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
    10f0:	eb 0a                	jmp    10fc <binary_semaphore_init+0x33>
	else
		semaphore->state = S_FREE;
    10f2:	8b 45 08             	mov    0x8(%ebp),%eax
    10f5:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
}
    10fc:	c9                   	leave  
    10fd:	c3                   	ret    

000010fe <binary_semaphore_down>:
void binary_semaphore_down(struct binary_semaphore* semaphore)
{
    10fe:	55                   	push   %ebp
    10ff:	89 e5                	mov    %esp,%ebp
    1101:	83 ec 28             	sub    $0x28,%esp
	//store amount of ticks left and prevent scheduler from switching
	int ticks;
	asm("pusha");
    1104:	60                   	pusha  
	ticks = getTicks();
    1105:	e8 72 f5 ff ff       	call   67c <getTicks>
    110a:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
    110d:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
    1114:	e8 5b f5 ff ff       	call   674 <alarm>
	asm("popa");
    1119:	61                   	popa   
	if (semaphore->state == S_LOCKED)
    111a:	8b 45 08             	mov    0x8(%ebp),%eax
    111d:	8b 40 04             	mov    0x4(%eax),%eax
    1120:	83 f8 01             	cmp    $0x1,%eax
    1123:	75 1c                	jne    1141 <binary_semaphore_down+0x43>
	{
		enqueue(semaphore);
    1125:	8b 45 08             	mov    0x8(%ebp),%eax
    1128:	89 04 24             	mov    %eax,(%esp)
    112b:	e8 4c ff ff ff       	call   107c <enqueue>
		uthread_sleep();
    1130:	e8 f1 fd ff ff       	call   f26 <uthread_sleep>
		alarm(0);
    1135:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
    113c:	e8 33 f5 ff ff       	call   674 <alarm>
	}
	semaphore->state = S_LOCKED;
    1141:	8b 45 08             	mov    0x8(%ebp),%eax
    1144:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
	//allow the thread to run its remaining time
	alarm(ticks);
    114b:	8b 45 f4             	mov    -0xc(%ebp),%eax
    114e:	89 04 24             	mov    %eax,(%esp)
    1151:	e8 1e f5 ff ff       	call   674 <alarm>

}
    1156:	c9                   	leave  
    1157:	c3                   	ret    

00001158 <binary_semaphore_up>:
void binary_semaphore_up(struct binary_semaphore* semaphore)
{
    1158:	55                   	push   %ebp
    1159:	89 e5                	mov    %esp,%ebp
    115b:	83 ec 28             	sub    $0x28,%esp
	int ticks;
	struct uthread *next;
	asm("pusha");
    115e:	60                   	pusha  
	ticks = getTicks();
    115f:	e8 18 f5 ff ff       	call   67c <getTicks>
    1164:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
    1167:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
    116e:	e8 01 f5 ff ff       	call   674 <alarm>
	asm("popa");
    1173:	61                   	popa   


	if ((next = dequeue(semaphore)) == 0)
    1174:	8b 45 08             	mov    0x8(%ebp),%eax
    1177:	89 04 24             	mov    %eax,(%esp)
    117a:	e8 9e fe ff ff       	call   101d <dequeue>
    117f:	89 45 f0             	mov    %eax,-0x10(%ebp)
    1182:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
    1186:	75 19                	jne    11a1 <binary_semaphore_up+0x49>
	{
		//no thread is waiting. release semaphore and restore alarm
		semaphore->state = S_FREE;
    1188:	8b 45 08             	mov    0x8(%ebp),%eax
    118b:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
		asm("pusha");
    1192:	60                   	pusha  
		alarm(ticks);
    1193:	8b 45 f4             	mov    -0xc(%ebp),%eax
    1196:	89 04 24             	mov    %eax,(%esp)
    1199:	e8 d6 f4 ff ff       	call   674 <alarm>
		asm("popa");
    119e:	61                   	popa   
    119f:	eb 0f                	jmp    11b0 <binary_semaphore_up+0x58>
	}
	else
	{
		//threads are waiting. wake up the next thread and yield.
		next->state = T_RUNNABLE;
    11a1:	8b 45 f0             	mov    -0x10(%ebp),%eax
    11a4:	c7 40 10 02 00 00 00 	movl   $0x2,0x10(%eax)
		uthread_yield();
    11ab:	e8 77 fc ff ff       	call   e27 <uthread_yield>
	}
}
    11b0:	c9                   	leave  
    11b1:	c3                   	ret    
